﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.UIElements;

namespace SkillEditor
{
    public class PortInputView : GraphElement, IDisposable
    {
        private EdgeControl m_EdgeControl;
        private VisualElement m_Container;
        private VisualElement m_Control;

        public PortInputView(VisualElement m_Control)
        {
            //styleSheets.Add(Resources.Load<StyleSheet>("Styles/PortInputView"));
            //pickingMode = PickingMode.Ignore;
            //ClearClassList();
            //m_Slot = slot;
            //m_SlotType = slot.concreteValueType;
            //AddToClassList("type" + m_SlotType);

            m_EdgeControl = new EdgeControl
            {
                @from = new Vector2(232f - 21f, 11.5f),
                to = new Vector2(232f, 11.5f),
                edgeWidth = 2,
                pickingMode = PickingMode.Ignore
            };
            Add(m_EdgeControl);

            m_Container = new VisualElement { name = "container" };
            {
                //CreateControl();

                m_Container.Insert(0, m_Control);

                var slotElement = new VisualElement { name = "slot" };
                {
                    slotElement.Add(new VisualElement { name = "dot" });
                }
                m_Container.Add(slotElement);
            }
            Add(m_Container);

            m_Container.Add(new VisualElement() { name = "disabledOverlay", pickingMode = PickingMode.Ignore });
            //RegisterCallback<CustomStyleResolvedEvent>(OnCustomStyleResolved);
        }

        //private void CreateControl()
        //{
        //    m_Control = slot.InstantiateControl();
        //    if (m_Control != null)
        //    {
        //        m_Container.Insert(0, m_Control);
        //    }
        //    else
        //    {
        //        // Some slot types don't support an input control, so hide this
        //        m_Container.visible = m_EdgeControl.visible = false;
        //    }
        //}

        public void Dispose()
        {
            //if (m_Control is IDisposable disposable)
            //    disposable.Dispose();
        }
    }
}